/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package armazemseujose.view;

import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author BRUNA
 */
public class cadastroVenda extends javax.swing.JFrame {

    private armazemSeuJoseView viewPrincipal;
    private DefaultTableModel model = new DefaultTableModel();

    public cadastroVenda() {
        initComponents();
    }

    public cadastroVenda(armazemSeuJoseView view) {
        initComponents();
        this.setVisible(true);
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);
        viewPrincipal = view;
        jTable1.setModel(model);
        model.addColumn("Item");
        model.addColumn("Quantidade");

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        itemVenda = new javax.swing.JTextField();
        addItem = new javax.swing.JButton();
        cadastrarVenda = new javax.swing.JButton();
        nomeClienteVenda = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        qtdItemVenda = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setTitle("Nova venda");

        jLabel1.setText("Cliente");

        jLabel2.setText("Item");

        itemVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemVendaActionPerformed(evt);
            }
        });

        addItem.setText("Adicionar");
        addItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addItemActionPerformed(evt);
            }
        });

        cadastrarVenda.setText("Salvar");
        cadastrarVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cadastrarVendaActionPerformed(evt);
            }
        });

        nomeClienteVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nomeClienteVendaActionPerformed(evt);
            }
        });

        jLabel3.setText("Quantidade");

        qtdItemVenda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                qtdItemVendaActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Title 1", "Title 2"
            }
        ));
        jScrollPane2.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(itemVenda, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(14, 14, 14)
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(qtdItemVenda, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(addItem))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(nomeClienteVenda)
                                .addGap(91, 91, 91))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 486, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cadastrarVenda))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nomeClienteVenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(itemVenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addItem)
                    .addComponent(jLabel3)
                    .addComponent(qtdItemVenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(169, 169, 169)
                        .addComponent(cadastrarVenda))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(23, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addItemActionPerformed
        getViewPrincipal().getControle().addItemVenda();
    }//GEN-LAST:event_addItemActionPerformed

    private void itemVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_itemVendaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_itemVendaActionPerformed

    private void nomeClienteVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nomeClienteVendaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nomeClienteVendaActionPerformed

    private void cadastrarVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cadastrarVendaActionPerformed
        try {
            getViewPrincipal().getControle().cadastrarVenda();
            JOptionPane.showMessageDialog(this, "Venda cadastrada com sucesso");
            nomeClienteVenda.setText("");
            model.setNumRows(0);
        } catch (Exception e) {
            System.out.println(e);
        }
    }//GEN-LAST:event_cadastrarVendaActionPerformed

    private void qtdItemVendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_qtdItemVendaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_qtdItemVendaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(cadastroVenda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(cadastroVenda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(cadastroVenda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(cadastroVenda.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new cadastroVenda().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addItem;
    private javax.swing.JButton cadastrarVenda;
    private javax.swing.JTextField itemVenda;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField nomeClienteVenda;
    private javax.swing.JTextField qtdItemVenda;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the addItem
     */
    public javax.swing.JButton getAddItem() {
        return addItem;
    }

    /**
     * @param addItem the addItem to set
     */
    public void setAddItem(javax.swing.JButton addItem) {
        this.addItem = addItem;
    }

    /**
     * @return the cadastrarVenda
     */
    public javax.swing.JButton getCadastrarVenda() {
        return cadastrarVenda;
    }

    /**
     * @param cadastrarVenda the cadastrarVenda to set
     */
    public void setCadastrarVenda(javax.swing.JButton cadastrarVenda) {
        this.cadastrarVenda = cadastrarVenda;
    }

    /**
     * @return the itemVenda
     */
    public javax.swing.JTextField getItemVenda() {
        return itemVenda;
    }

    /**
     * @param itemVenda the itemVenda to set
     */
    public void setItemVenda(javax.swing.JTextField itemVenda) {
        this.itemVenda = itemVenda;
    }

    /**
     * @return the jLabel1
     */
    public javax.swing.JLabel getjLabel1() {
        return jLabel1;
    }

    /**
     * @param jLabel1 the jLabel1 to set
     */
    public void setjLabel1(javax.swing.JLabel jLabel1) {
        this.jLabel1 = jLabel1;
    }

    /**
     * @return the jLabel2
     */
    public javax.swing.JLabel getjLabel2() {
        return jLabel2;
    }

    /**
     * @param jLabel2 the jLabel2 to set
     */
    public void setjLabel2(javax.swing.JLabel jLabel2) {
        this.jLabel2 = jLabel2;
    }

    /**
     * @return the jScrollPane1
     */
    /**
     * @param jScrollPane1 the jScrollPane1 to set
     */
    /**
     * @return the listItensVenda
     */
    /**
     * @return the nomeClienteVenda
     */
    public javax.swing.JTextField getNomeClienteVenda() {
        return nomeClienteVenda;
    }

    /**
     * @param nomeClienteVenda the nomeClienteVenda to set
     */
    public void setNomeClienteVenda(javax.swing.JTextField nomeClienteVenda) {
        this.nomeClienteVenda = nomeClienteVenda;
    }

    /**
     * @return the procurarCliente
     */
    /**
     * @return the viewPrincipal
     */
    public armazemSeuJoseView getViewPrincipal() {
        return viewPrincipal;
    }

    /**
     * @param viewPrincipal the viewPrincipal to set
     */
    public void setViewPrincipal(armazemSeuJoseView viewPrincipal) {
        this.viewPrincipal = viewPrincipal;
    }

    /**
     * @return the jLabel3
     */
    public javax.swing.JLabel getjLabel3() {
        return jLabel3;
    }

    /**
     * @param jLabel3 the jLabel3 to set
     */
    public void setjLabel3(javax.swing.JLabel jLabel3) {
        this.jLabel3 = jLabel3;
    }

    /**
     * @return the qtdItemVenda
     */
    public javax.swing.JTextField getQtdItemVenda() {
        return qtdItemVenda;
    }

    /**
     * @param qtdItemVenda the qtdItemVenda to set
     */
    public void setQtdItemVenda(javax.swing.JTextField qtdItemVenda) {
        this.qtdItemVenda = qtdItemVenda;
    }

    /**
     * @return the model
     */
    public DefaultTableModel getModel() {
        return model;
    }

    /**
     * @param model the model to set
     */
    public void setModel(DefaultTableModel model) {
        this.model = model;
    }

    /**
     * @return the jScrollPane2
     */
    public javax.swing.JScrollPane getjScrollPane2() {
        return jScrollPane2;
    }

    /**
     * @param jScrollPane2 the jScrollPane2 to set
     */
    public void setjScrollPane2(javax.swing.JScrollPane jScrollPane2) {
        this.jScrollPane2 = jScrollPane2;
    }

    /**
     * @return the jTable1
     */
    public javax.swing.JTable getjTable1() {
        return jTable1;
    }

    /**
     * @param jTable1 the jTable1 to set
     */
    public void setjTable1(javax.swing.JTable jTable1) {
        this.jTable1 = jTable1;
    }

}
